// 切换
$(".content .top p").click(function() {
        $(this).addClass("color").siblings().removeClass("color")
        $(".content .qiehuan .bottom").eq($(this).index()).addClass("hide").siblings().removeClass("hide")
    })
    // 手机号码验证
var Btn = document.getElementById("tijiao")
Btn.addEventListener("click", function() {
    var name = document.getElementsByName("sjh");
    var reg = /^1[3-5][0-9]{9}$/;
    var phonecode = document.getElementsByName("dx");
    var ger = /^[0-9]{4,6}$/;
    var name_value = name.value;
    var phonecode_value = phonecode.value;
    if (reg.test(name_value)) {
        $(".yellow").css("display", "none");
        if (ger.test(phonecode_value)) {
            $(".yellow").css("display", "none")
        } else {
            $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入短信验证码").css({
                "display": "inline-block",
                "top": "45px",
                "left": "243px",
            })
        }
    } else {
        $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入正确手机号").css({
            "display": "inline-block",
            "top": "0px",
            "left": "365px",
        })
    }
});
// // 第二页
var oBtn = document.getElementById("zhuce")
oBtn.addEventListener("click", function() {
    // 用户名
    var user = document.getElementById("userid");
    var yhm = /^[\w]{4,32}$/;
    var user_value = user.value;
    // 密码
    var userpw = document.getElementById("userpw");
    var mima = /^\w{6,}$/;
    var userpw_value = userpw.value;
    // 确认密码
    var userpw1 = document.getElementById("userpw1");
    var qr = /^\w{6,}$/;
    var userpw1_value = userpw1.value;
    // 手机号码
    var name = document.getElementById("size");
    var ji = /^1[3-5][0-9]{9}$/
    var name_value = name.value
        // 短信验证码
    var phonecode = document.getElementById("phonecode");
    var dx = /^[0-9]{4,6}$/
    var phonecode_value = phonecode.value
    var email = document.getElementById("email");
    var yx = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
    var email_value = email.value;
    if (email_value) {
        email_value = email_value
    } else {
        email_value = ""
    }
    if (yhm.test(user_value)) {
        $(".yellow").css("display", "none")
        if (mima.test(userpw_value)) {
            $(".yellow").css("display", "none")
            if (qr.test(userpw1_value) && userpw_value == userpw1_value) {
                $(".yellow").css("display", "none")
                if (ji.test(name_value)) {
                    $(".yellow").css("display", "none")
                    if (email_value) {
                        if (yx.test(email_value)) {
                            $(".yellow").css("display", "none")
                            if (dx.test(phonecode_value)) {
                                $(".yellow").css("display", "none")
                                $.getJSON("http://localhost/jiuji/api/register.php", {
                                    userid: user_value,
                                    userpw: userpw_value,
                                    size: name_value,
                                    email: email_value
                                }, function(
                                    data) {
                                    if (data) {
                                        console.log("注册成功");
                                        window.location.href =
                                            "http://localhost/jiuji/html/login.html";
                                    } else {
                                        console.log("手机号被占用");
                                    }
                                })
                            } else {
                                $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入短信验证码").css({
                                    "display": "inline-block",
                                    "top": "228px",
                                    "left": "245px",
                                })
                            }
                        } else {
                            $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入正确邮箱").css({
                                "display": "inline-block",
                                "top": "180px",
                                "left": "295px",
                            })
                        }
                    } else {
                        if (dx.test(phonecode_value)) {
                            $(".yellow").css("display", "none")
                            $.getJSON("http://localhost/jiuji/api/register.php", {}, function(
                                data) {
                                console.log(data);
                            })
                        } else {
                            $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入正确验证码").css({
                                "display": "inline-block",
                                "top": "244px",
                                "left": "227px",
                            })
                        }
                    }
                } else {
                    $(".yellow").fadeIn().delay(3000).fadeOut().html("请输入正确的手机号码!").css({
                        "display": "inline-block",
                        "top": "135px",
                        "left": "295px",
                    })
                }
            } else {
                $(".yellow").fadeIn().delay(3000).fadeOut().html("两次密码不一致!").css({
                    "display": "inline-block",
                    "top": "90px",
                    "left": "295px",
                })
            }
        } else {
            $(".yellow").fadeIn().delay(3000).fadeOut().html("密码最少六位哦!").css({
                "display": "inline-block",
                "top": "45px",
                "left": "295px",
            })
        }
    } else {
        $(".yellow").fadeIn().delay(3000).fadeOut().html("用户名应为4-32位字母或数字!").css({
            "display": "inline-block",
            "top": "0px",
            "left": "295px",
        })
    }
});